package com.kylin.hibernate;

import java.util.List;

import org.hibernate.criterion.Order;


/**
 * 查询信息包
 * 存放查询的必要信息，包括要查询的Class，查询的条件，排序条件
 * @author lzh
 *
 */
public class CriteriaInfo {
	private Class clz;
	private PropertyCondition[] pConditions;
	private Order orderby;
	private int pageSize;
	
	/**
	 * 取得一页的大小，当查询返回数据为页对象时会有页大小设置
	 * @return
	 */
	public int getPageSize() {
		return pageSize;
	}

	/**
	 * 设置一页的大小，当查询返回数据为页对象时会有页大小设置
	 * @param pageSize
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * @param clz  要查询的Class
	 * @param pConditions 查询的条件
	 * @param orderby  排序条件
	 */
	public CriteriaInfo(Class clz, PropertyCondition[]pConditions, Order orderby){
		this.clz = clz;
		this.pConditions = pConditions;
		this.orderby = orderby;
	}
	
	/**
	 * @param clz  要查询的Class
	 * @param pConditions 查询的条件（list中存放的必须是 PropertyCondition对象）
	 * @param orderby  排序条件
	 */
	public CriteriaInfo(Class clz, List pConditions){
		this.clz = clz;
		if(pConditions != null)
		this.pConditions = (PropertyCondition[])pConditions.toArray(new PropertyCondition[0]);
	}
		
	public Class getClz() {
		return clz;
	}
	public void setClz(Class clz) {
		this.clz = clz;
	}
	public Order getOrderby() {
		return orderby;
	}
	public void setOrderby(Order orderby) {
		this.orderby = orderby;
	}
	public PropertyCondition[] getPConditions() {
		return pConditions;
	}
	public void setPConditions(PropertyCondition[] conditions) {
		pConditions = conditions;
	}
	
	public String toString(){
		StringBuffer sb = new StringBuffer("-------CriteriaInfo-----");
		sb.append("\n ClzName :").append(this.getClz().getName());
		sb.append("\n pConditions.length :");
		if(this.pConditions != null)
			sb.append(this.pConditions.length);
		else
			sb.append(" null");
		sb.append("\n orderby :").append(this.orderby);
		return sb.toString();
	}
}
